<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="代表简介"></uni-navbar></view>

		<view class="form-box">
			<u-form :model="form" ref="uForm">
				<u-form-item class="form-item" required label="代表简介" labelPosition="top" prop="resume">
					<!-- block -->
					<u-input v-model="form.resume" inputAlign="left" type="textarea" placeholder="请输入代表简介" :clearable="false" :height="500" :maxlength="-1" />
				</u-form-item>
			</u-form>

			<view class="fiexd-btm"><u-button class="form-btn" :disabled="resume == form.resume" type="error" @click="confirm">保存</u-button></view>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			userInfoId: '',
			resume: '',
			form: {
				id: '',
				resume: ''
			},
			rules: {
				resume: [
					{
						required: true,
						message: '请输入代表简介',
						trigger: 'change'
					}
				]
			}
		};
	},
	onLoad(option) {
		this.loadLogin();
		// this.userInfoId = option.id;
		this.loadData();
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	onHide() {
		this.$ttsOff();
	},
	onUnload() {
		this.$ttsOff();
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.userInfo) {
				this.userId = this.userInfo.sysUser.id;
				this.userInfoId = this.userInfo.userInfoId;
			} else {
				this.$logout();
			}
		},
		loadData() {
			this.$request('/system/user-info/getDbRep?userId=' + this.userId).then((res) => {
				if (!res.data) {
					return false;
				}
				this.resume = res.data;
				this.form.resume = res.data;
			});
		},
		confirm() {
			this.$refs.uForm.validate((valid) => {
				if (!valid) {
					return false;
				} else {
					let data = {
						userId: this.userId,
						resume: this.form.resume
					};
					this.$request('/system/user-info/upDbRep', data, {
						load: true
					}).then((res) => {
						this.$msg(res.msg);
						setTimeout(() => {
							uni.navigateBack();
						}, 500);
						// this.loadData();
					});
				}
			});
		},
		navTo(url) {
			uni.navigateTo({
				url: url
			});
		},
		call(e) {
			uni.makePhoneCall({
				phoneNumber: e
			});
		},
		previewImage(list, idx) {
			let urls = [];
			list.forEach((item) => {
				urls.push(this.$imagePreview(item.path));
			});
			uni.previewImage({
				current: idx,
				urls: urls
			});
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.detail-info {
	padding: 0;

	.overflow {
		padding: 20rpx 30rpx;
	}
}

.img-box {
	padding: 20rpx 30rpx 0;
	display: flex;
	flex-wrap: wrap;

	.image {
		padding: 0 20rpx 20rpx 0;
		width: 160rpx;
		height: 160rpx;
	}
}

.form-box {
	.form-item {
		@include mp-flex;

		.input-text {
			width: 100%;
			padding: 11rpx 0;
			line-height: 48rpx;
			text-align: left;
		}
	}
}

.com-h2 {
	border-bottom: 2rpx solid $u-border-color;
}

.fiexd-btm {
	position: static;
	padding: 30rpx;
}
</style>
